<template>
  <div class="mod-config">
    <basic-container>
      <el-form :inline="true" ref="searchForm" :model="dataForm">
      </el-form>
      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column label="操作" width="220">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-collection" @click="getDetail(scope.row.billId)">详情</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="customerCard"  label="会员卡号"></el-table-column>
          <el-table-column prop="name" label="顾客姓名"></el-table-column>
          <el-table-column prop="billId" label="配镜(兑换)单号">
            <template slot-scope="scope">
              <el-link type="primary" @click="checkDetailByOrder(scope.row.billId)">{{scope.row.billId}}</el-link>
            </template>
          </el-table-column>
          <el-table-column prop="cardNum" label="储值卡卡号"></el-table-column>
          <el-table-column prop="createTime" label="储值时间"></el-table-column>
          <el-table-column prop="changeType" label="消费类型" :formatter="changeTypeFormatter"></el-table-column>
          <el-table-column prop="changeMoney" label="发生储值"></el-table-column>
          <el-table-column prop="balance" label="储值卡剩余"></el-table-column>
        </el-table>
      </div>
      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next"></el-pagination>
      </div>
      <!-- 详情页弹窗 -->
      <credit-detail v-if="detailVisible" ref="detailInfo"></credit-detail>
      <!-- 点击配镜单号跳转到配镜详情页 -->
      <order-info v-if="infoVisible" ref="infoDialog"></order-info>
    </basic-container>
  </div>
</template>

<script>
  import { getCreditCardInfo } from "@/api/eims/customer.js";
  import CreditDetail from './creditDetail'
  import { mapGetters } from "vuex";
  import OrderInfo from '@/views/eims/optician/glassesinfo/detail'

  export default {
    data() {
      return {
        infoVisible: false,
        dataForm: {
          key: ""
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        detailVisible: false
      };
    },
    computed: {
      ...mapGetters(["permissions"])
    },
    components: {
      CreditDetail,
      OrderInfo
    },
    methods: {
      // 初始化数据
      init(customerId,customerCard) {
        this.customerId = customerId
        this.customerCard = customerCard
        this.$nextTick(() => {
          this.getDataList()
        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }
        let params2 = {
          customerId : this.customerId,
          customerCard: this.customerCard
        }
        getCreditCardInfo(Object.assign(params1, params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records;
            this.totalPage = response.data.data.total;
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false;
        });
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      changeTypeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case 1:
            return '建卡'
            break
          case 2:
            return '结款'
            break
          case 3:
            return '充值'
            break
          case 4:
            return '提现'
            break
        }
      },
      getDetail(billId) {
        this.detailVisible = true
        this.$nextTick(() => {
          this.$refs.detailInfo.init(billId)
        })
      },
      //  查看配镜单详情
      checkDetailByOrder(order) {
        this.infoVisible = true;
        this.$nextTick(() => {
          this.$refs.infoDialog.init('', order, '配镜单详情');
        });
      },
    }
  };
</script>
